<template>
  <div>
    <div class="pds-tip">
      <el-form :inline="true" :model="pageData.params" class="filter">
        <el-form-item>
          <el-input v-model="pageData.params.applyNo" placeholder="请输入编号" clearable></el-input>
        </el-form-item>
        <el-form-item>
          <el-input v-model="pageData.params.plmModelNo" placeholder="请输入机型号" width="200px" clearable></el-input>
        </el-form-item>
        <el-form-item>
          <el-input v-model="pageData.params.title" placeholder="请输入标题" width="200px" clearable></el-input>
        </el-form-item>
        <el-form-item>
          <el-select v-model="customerArray" filterable remote placeholder='请选择客户' multiple :remote-method="getPdsCustomerByName" clearable>
            <el-option v-for="option in customerList" :key="option.id" :label="option.shortName" :value="option.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="search(pageData.params)">查询</el-button>
          <el-button type="danger" @click="reset">重置</el-button>
          <el-button type="success" @click="$router.push({path:'require/add/designUi'})">新增</el-button>
        </el-form-item>
      </el-form>
    </div>
    <el-table :data="tableData" border style=" margin: 15px auto;">
      <el-table-column width="50" align="center" label="序号">
        <template slot-scope="scope">
          {{(pageData.params.page-1)*pageData.params.limit+(scope.$index+1)}}
        </template>
      </el-table-column>
      <el-table-column prop="applyNo" label="编号" align="center" width='150px'></el-table-column>
      <el-table-column prop="title" label="标题" align="center"></el-table-column>
      <el-table-column prop="customerName" label="客户名称" align="center" width="100px"></el-table-column>
      <el-table-column prop="plmModelNo" label="机型号" align="center" width="160px"></el-table-column>
      <el-table-column prop="applyDate" label="申请时间" align="center" width='110px'></el-table-column>
      <el-table-column width="130px" align="center" label="状态">
        <template slot-scope="scope">
          <span v-if="scope.row.applyStatus===0">草稿</span>
          <span v-if="scope.row.applyStatus===1">审核中</span>
          <span v-if="scope.row.applyStatus===2">已发布</span>
          <span v-if="scope.row.applyStatus===3">已删除</span>
          <span v-if="scope.row.applyStatus===5">驳回</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" width="220px">
        <template slot-scope="scope">
          <el-button type="success" size="small" @click="$router.push({path:'require/view/designUi',query:{applyId:scope.row.id}})">查看
          </el-button>
          <el-button type="primary" size="small" @click="$router.push({path:'require/edit/designUi',query:{applyId:scope.row.id}})" v-if="scope.row.applyStatus==0 || scope.row.applyStatus==5">编辑
          </el-button>
          <el-button size="small" type="danger" v-if="scope.row.applyStatus===0 || scope.row.applyStatus===5" @click="handleDelete(scope.row)">删除</el-button>
          <el-button size="small" type="warning" v-if="scope.row.applyStatus===2" @click="$router.push({path:'require/view/designUi',query:{applyId:scope.row.id,type:'export'}})">导出</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination :pageData="pageData.params" @pageChange="changePage" @changeSize="changeSize"></pagination>
  </div>
</template>

<script>
import * as api from '@/api/packing/require/index';
import * as saleApi from '@/api/sale/index';

export default {
  name: 'requireGraphic',
  data() {
    return {
      customerList: [],
      customerArray: [],
      pageData: {
        params: {
          page: 1,
          limit: 10,
          applyNo: '',
          plmModelNo: '',
          title: '',
          customerName: '',
          total: 100,
        },
        list: []
      },
      tabName: 'first',
      tableData: []
    };
  },
  created() {
    this.getList();
  },
  activated() {
    this.getList();
  },
  methods: {
    // 客户筛选下拉框选项
    getPdsCustomerByName(val) {
      if (val !== '') {
        saleApi
          .getPdsCustomerByName({
            customerName: val
          })
          .then(res => {
            this.customerList = res.data;
          });
      }
    },
    handleDelete(row) {
      console.log(row);
      this.$confirm('此操作将永久删除该条数据, 是否继续?', '提示', {
        type: 'warning'
      }).then(() => {
        const params = { id: row.id };
        api.removePlan1(params).then(response => {
          console.log(response);
          if (response.code === 200) {
            this.$message({
              type: 'success',
              message: '删除成功!'
            });
            this.getList();
          }
        });
      });
    },
    getList() {
      this.pageData.params.customerIds = this.customerArray.join(
        ','
      );
      const params = this.pageData.params;
      api.getList1(params).then(response => {
        if (response.code === 200) {
          this.tableData = response.data.rows;
          this.pageData.params.total = response.data.total;
          // console.log(this.pageData.params)
        }
      });
    },
    search() {
      this.pageData.params.page = 1;
      this.getList();
    },
    changePage(pageData) {
      this.pageData.params.page = pageData.page;
      this.getList();
    },
    changeSize(pageSize) {
      this.pageData.params.limit = pageSize;
      this.pageData.params.page = 1;
      this.getList();
    },
    reset() {
      this.pageData.params = {
        page: 1,
        limit: 10,
        applyNo: '',
        plmModelNo: '',
        title: '',
        customerName: '',
        customerArray: []
      };
      this.getList();
    }
  }
};
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
.bigbox {
  width: 100%;
  background: #f5f5f5;
  overflow: hidden;
}
.pds-tip-green .filter {
  padding-top: 29px !important;
}
.el-header,
.el-footer {
  width: 300px;
  background-color: #ffffff;
  color: #333;
  text-align: center;
  line-height: 60px;
  border: 1px solid #ccc;
}

.el-aside {
  background-color: #d3dce6;
  color: #333;
  text-align: center;
  line-height: 200px;
}

.el-main {
  width: 300px;
  background-color: #fff;
  color: #333;
  text-align: center;
  line-height: 160px;
  margin-bottom: 30px;
  border: 1px solid #ccc;
}

body > .el-container {
  margin-bottom: 40px;
}

.el-container:nth-child(5) .el-aside,
.el-container:nth-child(6) .el-aside {
  line-height: 260px;
}

.el-container:nth-child(7) .el-aside {
  line-height: 320px;
}

.custom-tree-node {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 14px;
  padding-right: 8px;
}

.el-tabs__header {
  margin: 0;
}

.pds-tip-green {
  padding: 8px 16px;
  background-color: #f8f8f8;
  border-radius: 4px;
  border-left: 5px solid #42b983;
  margin: 0 0 20px;
  p {
    font-size: 14px;
    color: #5e6d82;
    line-height: 1.5em;
    margin-top: 5px;
    margin-bottom: 5px;
  }
}
</style>

